package org.seafloor.system.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.seafloor.common.model.SystemConstants;
import org.seafloor.system.dao.UserDao;
import org.seafloor.system.model.UserVO;
import org.seafloor.system.service.UserService;

import com.opensymphony.xwork2.ActionSupport;


public class UserAction extends ActionSupport {
	private UserVO userVO ;
	private UserService userService;
	private List<UserVO> userList=new ArrayList<UserVO>();
	public String errorMsg;

	public String findUserList() {
		System.out.println("访问Action！findUserList");
		try {
			userList = userService.findUserList();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "userList";
	}
	
	public String modifyUserById() {
		System.out.println("访问Action！modifyUserById");
		try {
			userVO = userService.findUserById(userVO);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "userModify";
	}
	
	public String insertUser(){
		System.out.println("访问Action！insertUser");
		try {
			UserVO u=userService.findUserByLoginName(userVO);
			if(null!=u){
				errorMsg="该用户名已存在,请重新输入!";
				return "userAdd";
			}
			userService.saveUser(userVO);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return findUserList();
	}
	
	public String updateUser(){
		System.out.println("访问Action！updateUser");
		try {
			userService.updateUser(userVO);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return findUserList();
	}
	
	public String deleteUser(){
		System.out.println("访问Action！deleteUser");
		try {
			int i = userService.deleteUser(userVO);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return findUserList();
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public List<UserVO> getUserList() {
		return userList;
	}

	public void setUserList(List<UserVO> userList) {
		this.userList = userList;
	}

	public UserVO getUserVO() {
		return userVO;
	}

	public void setUserVO(UserVO userVO) {
		this.userVO = userVO;
	}

	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}
	
}
